/**
 * 
 */
package com.lb.store.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;


/**
 * @author TieSheng
 * 2010-8-16 ����11:29:46
 */
public class ConnMysql {
	
	public static void main(String[] args) {
		ConnMysql t = new ConnMysql();
		try {
			try{
				t.insertData();
			}catch(MySQLIntegrityConstraintViolationException e){
				//e.printStackTrace();
				System.out.println(e.getMessage());
			}	
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	void insertData() throws Exception{
		Connection conn = getConn();
		Statement stmt = conn.createStatement();
		//int i = stmt.executeUpdate();
		stmt.addBatch("delete from kfc_roster_list_01 where ROSTER_GROUP='testGroup' and value ='test'");
		stmt.addBatch("INSERT INTO kfc_roster_list_01 (ROSTER_GROUP,VALUE,GMT_CREATE) values (\"testGroup\",\"test\",now())");
		stmt.addBatch("delete from kfc_roster_list_01 where ROSTER_GROUP='testGroup' and value ='test'");
		stmt.addBatch("INSERT INTO kfc_roster_list_01 (ROSTER_GROUP,VALUE,GMT_CREATE) values (\"testGroup\",\"test\",now())");
		stmt.addBatch("delete from kfc_roster_list_01 where ROSTER_GROUP='testGroup' and value ='test'");
		stmt.addBatch("INSERT INTO kfc_roster_list_01 (ROSTER_GROUP,VALUE,GMT_CREATE) values (\"testGroup\",\"test\",now())");
		stmt.executeBatch();
		System.out.println("");
		stmt.close();
		conn.close();
	}
    
	Connection getConn() throws Exception{
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.213.59/ctu_test?useUnicode=true&characterEncoding=GBK","root","hello123");		
		return conn;
	}

}
